package com.fare.taluo.web.action;



import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fare.taluo.BaseFdcAction;
import com.fare.taluo.application.CaptureDataExportApplication;
import com.fare.taluo.application.plane.channel.SourceApplication;
import com.fare.taluo.vo.core.SourceEntityVO;

@Namespace("/")
@Controller("captureDataExportAction")
@Scope("prototype")
public class CaptureDataExportAction extends BaseFdcAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 7744485845738030878L;
	private static final Logger logger = LoggerFactory.getLogger(CaptureDataExportAction.class);
	private String returnPageURL;
	private List<SourceEntityVO> seList;//渠道list
	private String status;
	
	@Resource(name="captureDataExportApplicationImpl")
	private CaptureDataExportApplication captureDataExportApplication;
	
	@Resource(name="sourceApplication")
	private SourceApplication sourceApplication;

	
	private String grapDate;//抓取时间
	private String  channels;//网站名字
	
	
	
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getGrapDate() {
		return grapDate;
	}
	public void setGrapDate(String grapDate) {
		this.grapDate = grapDate;
	}
	
	
	public String getChannels() {
		return channels;
	}
	public void setChannels(String channels) {
		this.channels = channels;
	}
	public String getReturnPageURL() {
		return returnPageURL;
	}
	public void setReturnPageURL(String returnPageURL) {
		this.returnPageURL = returnPageURL;
	}
	public List<SourceEntityVO> getSeList() {
		return seList;
	}
	public void setSeList(List<SourceEntityVO> seList) {
		this.seList = seList;
	}

	
	/**
	 * 输入页
	 * */
	public String input(){
		returnPageURL = "/fare/zqsjdcForm.jsp";
		seList = sourceApplication.findBycrawlStatus(1);
		return "dispatcher";
	}
	
	public String export(){
		HttpServletResponse  response = ServletActionContext.getResponse();
		
			try {
				captureDataExportApplication.exportExcel(response,request,grapDate, channels);
			} catch (Exception e) {
				if(e.getMessage()=="nodataerror"){
					status = "nodata";
				}else{
					status = "error";
				}
			}
		seList = sourceApplication.findBycrawlStatus(1);
		returnPageURL = "/fare/zqsjdcForm.jsp";
		return "dispatcher";
	}

}
